<?php

class UserController extends \BaseController {

	public function getLogin()
	{
		return View::make("users/login");
	}
	
	public function postLogin()
	{	
		$validator =  Validator::make(Input::all(), [
			"username" => "required",
			"password" => "required"
		]);

		if ($validator->passes()) {
			$credentials = [
				"username" => Input::get("username"),
				"password" => Input::get("password")
			];

			if (Auth::attempt($credentials)) {
				return Redirect::to('/');
			}

			return Redirect::back()->withErrors([
				"password" => ["Credentials invalid."]
			]);
		} 
		
		return Redirect::back()
			->withInput()
			->withErrors($validator);
		
	}
	
	public function getLogout()
	{
		Auth::logout();
		return Redirect::to('/');
	}

// 	protected function isPostRequest()
// 	{		
// 		return Input::server("REQUEST_METHOD") == "POST";
// 	}
	
// 	public function profile()
// 	{
// 		return View::make("users/profile");
// 	}
	
	
// 	public function request()
// 	{
// 		if ($this->isPostRequest()) {
// 			$response = Password::remind(Input::only("email"));
	
// 			if ($response === Password::INVALID_USER) {
// 				return Redirect::back()
// 					->withInput()
// 					->with("error", Lang::get($response));
// 			}
	
// 			return Redirect::back()
// 				->with("status", Lang::get($response));
// 		}
	
// 		return View::make("users/request");
// 	}
	
// 	public function reset($token)
// 	{
// 		if ($this->isPostRequest()) {
// 			$credentials = Input::only(
// 				"email",
// 				"password",
// 				"password_confirmation"
// 			) + compact("token");
	
// 			$response = $this->resetPassword($credentials);
	
// 			if ($response === Password::PASSWORD_RESET) {
// 				return Redirect::route("user.profile");
// 			}
	
// 			return Redirect::back()
// 				->withInput()
// 				->with("error", Lang::get($response));
// 		}
	
// 		return View::make("users/reset", compact("token"));
// 	}
	
// 	protected function resetPassword($credentials)
// 	{
// 		return Password::reset($credentials, function($user, $pass) {
// 			$user->password = Hash::make($pass);
// 			$user->save();
// 		});
// 	}
	
}
